class Solution(object):
    def minSideJumps(self, obstacles):
        last = [0, float('inf'), 0, float('inf')]
        n = len(obstacles)
        for i in range(1, n):
            if obstacles[i] > 0:
                for j in range(1, 4):
                    if obstacles[i - 1] != j and j != obstacles[i]:
                        last[j] = min(last[j], last[obstacles[i]] + 1)
                last[obstacles[i]] = float('inf')
        return min(last[1:])


data = Solution()
obstacles = [0, 1, 2, 3, 0]
print(data.minSideJumps(obstacles))
